package com.mcx.modules.controller;

import com.mcx.modules.PlayerEntity;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Data
public class WorldMapSceneEntity {

    /// <summary>
    /// 世界地图编号
    /// </summary>
    private int WorldMapSceneId;

    private HashMap<Integer, PlayerEntity> m_RoleDic;
    private ArrayList<PlayerEntity> m_RoleList;

    public WorldMapSceneEntity(int worldMapSceneId)
    {
        WorldMapSceneId = worldMapSceneId;
        m_RoleDic = new HashMap<Integer, PlayerEntity>();
        m_RoleList = new ArrayList<PlayerEntity>();
    }

    /// <summary>
    /// 角色进入场景
    /// </summary>
    /// <param name="role"></param>
    public void RoleEnter(PlayerEntity playerEntity)
    {
        m_RoleDic.put(playerEntity.id, playerEntity);
    }

    /// <summary>
    /// 角色离开场景
    /// </summary>
    /// <param name="roleId"></param>
    public void RoleLeave(int playerId)
    {
        if (m_RoleDic.containsKey(playerId))
        {
            m_RoleDic.remove(playerId);
        }
    }

    /// <summary>
    /// 获取当前场景所有角色
    /// </summary>
    /// <returns></returns>
    public ArrayList<PlayerEntity> GetRoleList()
    {
        m_RoleList.clear();

        m_RoleDic.forEach((key, value) -> m_RoleList.add(value));

        return m_RoleList;
    }
}
